Imports DevExpress.XtraEditors

Public Class DialogRole
    Inherits templateFormDialog
    Private execvalue As String
    Public Overrides Sub SetReset()
        MyBase.SetReset()
        Me.Close()
    End Sub
    Private Sub refreshEdit()
        koderole.Text = ""
        role.Text = ""
        koderole.Properties.ReadOnly = True
        role.Properties.ReadOnly = True
    End Sub
    Private Sub RadioGroup1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioGroup1.SelectedIndexChanged
        If RadioGroup1.SelectedIndex = 0 Then
            koderole.Text = ""
            role.Text = ""
            koderole.Properties.ReadOnly = False
            role.Properties.ReadOnly = False
            execvalue = "add"
        ElseIf RadioGroup1.SelectedIndex = 1 Then
            refreshEdit()
            GridView1_Click(sender, e)
            role.Properties.ReadOnly = False
            execvalue = "edit"
        ElseIf RadioGroup1.SelectedIndex = 2 Then
            refreshEdit()
            GridView1_Click(sender, e)
            execvalue = "delete"
        End If
    End Sub
    Private Sub refreshdata()
        Dim dt As New DataTable
        If Utils.executeSP("proc_role", New Object() {"select", koderole.Text, role.Text}, dt) Then
            If dt IsNot Nothing Then
                GridControl1.DataSource = dt
            End If
        End If
    End Sub
    Private Sub DialogRole_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        refreshdata()
    End Sub
    Private contsparam() As String = {"koderole", "role"}
    Private Sub GridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridView1.Click
        Dim obj As DataRow
        obj = GridView1.GetDataRow(GridView1.FocusedRowHandle)
        For Each sctl As String In contsparam
            Dim ctl As Control()
            ctl = Me.Controls.Find(sctl, True)
            If ctl IsNot Nothing And ctl.Length > 0 Then
               If TypeOf ctl(0) Is TextEdit Then
                    Dim ctltxt As New TextEdit
                    ctltxt = CType(ctl(0), TextEdit)
                    ctltxt.Text = IIf(IsDBNull(obj(sctl)), "", obj(sctl).ToString)
                End If
            End If

        Next
    End Sub

    Public Overrides Sub SetSimpan()
        MyBase.SetSimpan()
        Dim retval As Boolean = True
        If koderole.Text = "" Then
            retval = False
        End If
        If role.Text = "" Then
            retval = False
        End If
        If Not retval Then
            MsgBox("Data KodeRole / Role Tidak Valid", MsgBoxStyle.Exclamation)
            Exit Sub
        End If
        Dim dt As New DataTable
        If Utils.executeSP("proc_role", New Object() {execvalue, koderole.Text, role.Text}, dt) Then
            If dt IsNot Nothing Then
                MessageBox.Show(dt.Rows(0)("pesan").ToString)
                refreshdata()
                refreshEdit()
                RadioGroup1.SelectedIndex = -1
                'Utils.exec_SP("proc_zloguser", New Object() {"add", "proc_role|add", TextKodeRole.Text, Session.username})
            End If
        End If

    End Sub
End Class